package br.ufla.pgcc.oomeasures.astvisitors;

import java.math.BigDecimal;
import java.math.RoundingMode;

import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.CompilationUnit;

public class MethodHidingFactorVisitor extends ASTVisitor{
	private double methodHidingFactorIndex;
	
	@Override
	public boolean visit(CompilationUnit unit) {
		
		calculateMethodHidingFactor(unit);
		
		return super.visit(unit);
	}
	
	/**
	 * The MHF is calculated by [sum(MV) / Number of methods],
	 * where MV is number of other classes where method is visible.
	 */
	private void calculateMethodHidingFactor(CompilationUnit unit){
		
		BigDecimal numPrivateMethods = new BigDecimal(MethodVisitor.getNumberOfProjectPrivateMethods());
		BigDecimal numClasses = new BigDecimal(ClassVisitor.getNumOfProjectClasses());
		BigDecimal numMethods = new BigDecimal(MethodVisitor.getNumberOfProjectMethods());
		
		BigDecimal numerator = numPrivateMethods.divide(numClasses, 2, RoundingMode.UP);
		
		methodHidingFactorIndex = numerator.divide(numMethods, 2, RoundingMode.UP).doubleValue();
		
	}
	
	public double getMethodHidingFactor(){
		return methodHidingFactorIndex;
	}
}
